package com.ruoyi.conbined_product.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.conbined_product.domain.CombineProductData;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.conbined_product.service.ICombinedProductDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品重置Controller
 *
 * @author ruoyi
 * @date 2024-07-05
 */
@RestController
@RequestMapping("/conbined_product/conbined_product")
public class CombinedProductDataController extends BaseController
{
    @Autowired
    private ICombinedProductDataService combinedProductDataService;

    /**
     * 查询商品重置列表
     */
    @PreAuthorize("@ss.hasPermi('conbined_product:conbined_product:list')")
    @GetMapping("/list")
    public TableDataInfo list(CombineProductData combineProductData)
    {
        startPage();
        List<CombineProductData> list = combinedProductDataService.selectCombinedProductDataList(combineProductData);
        return getDataTable(list);
    }

    /**
     * 导出商品重置列表
     */
    @PreAuthorize("@ss.hasPermi('conbined_product:conbined_product:export')")
    @Log(title = "商品重置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CombineProductData combineProductData)
    {
        List<CombineProductData> list = combinedProductDataService.selectCombinedProductDataList(combineProductData);
        ExcelUtil<CombineProductData> util = new ExcelUtil<CombineProductData>(CombineProductData.class);
        util.exportExcel(response, list, "商品重置数据");
    }

    /**
     * 获取商品重置详细信息
     */
    @PreAuthorize("@ss.hasPermi('conbined_product:conbined_product:query')")
    @GetMapping(value = "/{combinedId}")
    public AjaxResult getInfo(@PathVariable("combinedId") Long combinedId)
    {
        return success(combinedProductDataService.selectCombinedProductDataByCombinedId(combinedId));
    }

    /**
     * 新增商品重置
     */
    @PreAuthorize("@ss.hasPermi('conbined_product:conbined_product:add')")
    @Log(title = "商品重置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CombineProductData combineProductData)
    {
        return toAjax(combinedProductDataService.insertCombinedProductData(combineProductData));
    }

    /**
     * 修改商品重置
     */
    @PreAuthorize("@ss.hasPermi('conbined_product:conbined_product:edit')")
    @Log(title = "商品重置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CombineProductData combineProductData)
    {
        return toAjax(combinedProductDataService.updateCombinedProductData(combineProductData));
    }

    /**
     * 删除商品重置
     */
    @PreAuthorize("@ss.hasPermi('conbined_product:conbined_product:remove')")
    @Log(title = "商品重置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{combinedIds}")
    public AjaxResult remove(@PathVariable Long[] combinedIds)
    {
        return toAjax(combinedProductDataService.deleteCombinedProductDataByCombinedIds(combinedIds));
    }
}
